package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dkd.manage.domain.StockRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.Product;
import com.dkd.manage.service.IProductService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 仓库出入库管理Controller
 * 
 * @author yuwensheng
 * @date 2024-10-26
 */
@RestController
@RequestMapping("/manage/product")
public class ProductController extends BaseController
{
    @Autowired
    private IProductService productService;

    /**
     * 查询仓库出入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(Product product)
    {
        startPage();
        List<Product> list = productService.selectProductList(product);
        return getDataTable(list);
    }

    /**
     * 导出仓库出入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:product:export')")
    @Log(title = "仓库出入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Product product)
    {
        List<Product> list = productService.selectProductList(product);
        ExcelUtil<Product> util = new ExcelUtil<Product>(Product.class);
        util.exportExcel(response, list, "仓库出入库管理数据");
    }

    /**
     * 获取仓库出入库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productService.selectProductById(id));
    }

    /**
     * 新增仓库出入库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:product:add')")
    @Log(title = "仓库出入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Product product)
    {
        return toAjax(productService.insertProduct(product));
    }

    /**
     * 修改仓库出入库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:product:edit')")
    @Log(title = "仓库出入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Product product)
    {
        return toAjax(productService.updateProduct(product));
    }

    /**
     * 删除仓库出入库管理
     */
    @PreAuthorize("@ss.hasPermi('manage:product:remove')")
    @Log(title = "仓库出入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productService.deleteProductByIds(ids));
    }

    /**
     * 处理商品出入库
     */
    @PreAuthorize("@ss.hasPermi('manage:product:stock')")
    @Log(title = "仓库出入库管理", businessType = BusinessType.UPDATE)
    @PostMapping("/stock")
    public AjaxResult stock(@RequestBody StockRequest stockRequest) {
        return toAjax(productService.stockProduct(stockRequest));
    }
}
